package com.yuxi;

/**
 * Created by yuxi on 17/2/1.
 */
public class SynYeild {
    public static void main(String[] args) {
        MyThread my = new MyThread();
        new Thread(my).start();
        new Thread(my).start();

    }

    static class MyThread implements Runnable {
        public void run() {
            synchronized (this) {
                for (int i = 0; i < 1000; i++) {
                    System.out.printf("%s [%d]:%d\n", Thread.currentThread().getName(), Thread.currentThread().getPriority(), i);
                    if (i % 4 == 0) {
                        Thread.yield();
                    }
                }
            }
        }
    }
}
